package cn.com.lms.business.cozmgt.persistence.repository;

import cn.com.lms.business.cozmgt.persistence.entity.CatalogManage;

import com.bnzj.core.persistence.repository.BaseRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * @Author: 16266
 * @DateTime: 2020/3/13 14:16
 * @Description: 目录管理持久层
 */
@Repository
public interface CatalogManageRepository extends BaseRepository<CatalogManage,Long> {


    /**
     * 查询目录树节点
     * @return
     */
    @Query(value = "SELECT course.id,course.parentId,CONCAT(course.dir_name,'(',course.stuNum,')') as name,course.sort from(SELECT c.id, c.parent_id as parentId, c.dir_name,c.sort" +
            ",( SELECT count( i.id ) FROM bnz_course_info i WHERE i.category_id = c.id and i.is_delete = 0 ) AS stuNum   FROM bnz_catalog_manage c  ) course", nativeQuery = true)
    List<Map>  queryCategory();
}
